import { Component, Inject, OnInit, ViewChild } from '@angular/core';
import { ControlWidget } from '@delon/form';
import { ItcoreConnectionComponent } from '@shared/itcore/components/common/db/connection.component';
import { NzUploadFile } from 'ng-zorro-antd/upload';
import { Observable, Observer } from 'rxjs';

@Component({
  selector: 'app-itcore-db-cnnect',
  template: `
    <sf-item-wrap [id]="id" [schema]="schema" [ui]="ui" [showError]="showError" [error]="error" [showTitle]="schema.title">

     <button nz-button nzType="default" (click)='drawerCollectVisible=true' ><i nz-icon nzType="arrow-right" nzTheme="outline"></i>{{currentConnectTitle}}</button>
     <nz-drawer nzTitle="选择数据库连接" [nzVisible]="drawerCollectVisible" nzWidth="30%" (nzOnClose)="closeDrawer()">
      <app-itcore-connection #connection (checkSuccess)='checkConnect($event)' [value]='value'></app-itcore-connection>
    </nz-drawer>
    </sf-item-wrap>
  `,
  styles: [
    `
     
    `,
  ],
})
// 选择数据连接
export class DBConnectWidgetComponent extends ControlWidget implements OnInit {
  static readonly KEY = 'itcore-db-connect';

  drawerCollectVisible = false;
  currentConnectTitle = '点击选择连接对象';


  closeDrawer() {
    this.drawerCollectVisible = false;
  }
  ngOnInit(): void {
  }
  change(value: string) {
    this.setValue(value);
    if (this.ui.change) {
      this.ui.change(value);
    }

  }
  checkConnect(val) {
    this.currentConnectTitle = val.Title;
    this.drawerCollectVisible = false;
    setTimeout(() => {
      this.change(val.Id);
    }, 100);
  }
}
